﻿// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
//     <version>$Revision$</version>
// </file>

using System.Collections.Generic;

namespace ICSharpCode.TextEditor.Document
{
    /// <summary>
    ///     This interface is used to describe a span inside a text sequence
    /// </summary>
    public interface ISegment
    {
        /// <value>
        ///     The offset where the span begins
        /// </value>
        int Offset { get; set; }

        /// <value>
        ///     The length of the span
        /// </value>
        int Length { get; set; }
    }

    public class SegmentComparer : IComparer<ISegment>
    {
        public int Compare(ISegment x, ISegment y)
        {
            if (x == null)
            {
                if (y == null)
                    return 0;

                // If x is null and y is not null, y
                // is greater.
                return -1;
            }

            // If x is not null and y is null, x is greater.
            if (y == null)
                return 1;

            var retval = x.Offset.CompareTo(y.Offset);
            if (retval != 0)
                return retval;

            return x.Length.CompareTo(y.Length);
        }
    }
}